package com.kangyi.admin.controller;

import com.kangyi.admin.service.OperationSituationService;
import com.kangyi.dto.ModifyStatusDTO;
import com.kangyi.dto.OperationPageQueryDTO;
import com.kangyi.result.PageResult;
import com.kangyi.result.Result;
import com.kangyi.vo.OperationDetailVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

/**
 * @author Blank
 * @version 1.0
 */
@RestController
@RequestMapping("/admin/operation")
@Slf4j
@Api(tags = "超级管理员-运营情况相关接口")
public class OperationSituationController {

    @Autowired
    private OperationSituationService operationSituationService;

    @GetMapping("/page")
    @ApiOperation("运营情况分页查询")
    public Result<PageResult> pageQuery(OperationPageQueryDTO operationPageQueryDTO){
        log.info("运营情况分页查询:{}",operationPageQueryDTO);
        try {
            PageResult pageResult = operationSituationService.pageQuery(operationPageQueryDTO);
            return Result.success(pageResult,"查询成功！");
        } catch (Exception e) {
            return Result.success(e.getMessage());
        }
    }

    @GetMapping("/detail/{nursingHomeId}")
    @ApiOperation("查询运营养老院基本信息")
//    @Cacheable(cacheNames = "operationSituation_", key = "'adminDetail_'+#nursingHomeId")
    public Result<OperationDetailVO> detailOperation(@PathVariable Integer nursingHomeId){
        log.info("查询运营养老院基本信息:{}",nursingHomeId);
        try {
            OperationDetailVO operationDetailVO = operationSituationService.detailOperation(nursingHomeId);
            return Result.success(operationDetailVO,"查询成功！");
        } catch (Exception e) {
            return Result.success(e.getMessage());
        }
    }

    @PutMapping("/modify")
    @ApiOperation("修改养老院状态")
    @CacheEvict(cacheNames = "operationSituation_", allEntries = true)
    public Result modifyStatus(@RequestBody ModifyStatusDTO modifyStatusDTO){
        log.info("修改养老院状态:{}",modifyStatusDTO);
        try {
            operationSituationService.modifyStatus(modifyStatusDTO);
            return Result.success("修改成功");
        } catch (Exception e) {
            return Result.success(e.getMessage());
        }
    }
}
